package com.Imp;

import com.entity.OManagement;
import com.mapper.OManagementMapper;
import com.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class OManagementMapperImpl implements OManagementMapper {
    public List<OManagement> getOrdersBycustomerId(String customerId){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()){
            return sqlSession.selectList("com.mapper.OManagementMapper.getOrdersBycustomerId", customerId);
        }
    }

    public List<OManagement> getOrdersBystoreId(String storeId){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()){
            return sqlSession.selectList("com.mapper.OManagementMapper.getOrdersBystoreId", storeId);
        }
    }

    public List<OManagement> getOrdersBydeliveryId(String deliveryId){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()){
            return sqlSession.selectList("com.mapper.OManagementMapper.getOrdersBydeliveryId", deliveryId);
        }
    }
    public OManagement  getOrdersByorderId(int orderId) {
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            return sqlSession.selectOne("com.mapper.OManagementMapper.getOrdersByorderId", orderId);
        }
    }
    public void addOrder(OManagement order){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.insert("com.mapper.OManagementMapper.addOrder",order);
            sqlSession.commit();  // 提交事务
        }
    }
    public void updateOrder(OManagement order){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.insert("com.mapper.OManagementMapper.updateOrder",order);
            sqlSession.commit();  // 提交事务
        }
    }
    public void deleteOrder(int orderId){
        try (SqlSession sqlSession = MyBatisUtil.openSqlSession()) {
            sqlSession.delete("com.mapper.OManagementMapper.deleteOrder",orderId);
            sqlSession.commit();  // 提交事务
        }
    }
}
